%plot the error after 4000 iterations
function plotconv4(dir,m,prefs)
files=[2 2; 2 3; 2 5; 2 10; 3 2; 5 2; 10 2];
numfiles = length(files);
avg_col=10;
std_col=11;
avdata=[numfiles];
stdata=[numfiles];
for i=1:numfiles
    alldata=load(strcat(dir,'\m',int2str(m),'_n',int2str(files(i,1)),'_d',int2str(files(i,2)),'_',prefs,'.all.results'));
    num=length(alldata);
    numexp=alldata(num,1)+1;
    numblocks=alldata(num,2)+1;
    range = numblocks:numblocks:num;
    for j=1:numexp
        avdata(i,j)=alldata(j*numblocks,avg_col);
        stdata(i,j)=alldata(j*numblocks,std_col);
    end;
end;
    


x=1:numexp;
%a1 = x0:(x1-x0)/10:x1;


%for a1=.4
%g=1.5
lw=2;
fs=12;
set(gca,'FontSize',fs);
colors='ymcrgby';
legendstr=[];
for i=1:numfiles
    errorbar(x,avdata(i,:),stdata(i,:),'Color',colors(i),'LineWidth', lw);
    legendstr=strvcat(legendstr,strcat('n=',int2str(files(i,1)),',d=',int2str(files(i,2))));
    hold on;
end;
xlim([0 numexp]);
legend(legendstr);
xlabel('preferences', 'FontSize', fs);
ylabel('num. iterations to converge', 'FontSize', fs);
title('Average Error after 5000 iterations');
hold off;


name = strcat('./conv4_m',int2str(m),'_',prefs);
print('-depsc',strcat(name, '.eps'));
%print('-dpdf',strcat(name, '.pdf'));
end

